package scau.erps.view.base;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import scau.erps.app.Erps;
import scau.erps.service.LoanService;
import scau.erps.service.impl.LoanServiceImpl;
import scau.erps.view.SandPanel;


/**
 * 高利贷对话框
 * @author ZJC
 *
 */
public class UsuriousLoanDialog extends JDialog {
	private static final long serialVersionUID = 1L;
	private final JPanel contentPanel = new JPanel();
	private LoanService loanService=Erps.getIocInstance().get(LoanServiceImpl.class);
	private DecisionPanel superPanel;
	public UsuriousLoanDialog(DecisionPanel superPanel) {
		this.superPanel=superPanel;
		setModal(true);
		setTitle("申请高利贷");
		setSize( 300, 225);
		setLocationRelativeTo(null);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);		
		JLabel Label1 = new JLabel("贷款额度");
		Label1.setBounds(30, 20, 60, 30);
		contentPanel.add(Label1);		
		JLabel Label2 = new JLabel("借款时间");
		Label2.setBounds(30, 60, 60, 30);
		contentPanel.add(Label2);		
		final JComboBox<String> amountComboBox = new JComboBox<String>();
		amountComboBox.setModel(new DefaultComboBoxModel<String>(new String[] {"10M", "20M", "30M", "40M"}));
		amountComboBox.setBounds(120, 20, 90, 30);
		contentPanel.add(amountComboBox);		
		final JComboBox<String> quarterComboBox = new JComboBox<String>();
		quarterComboBox.setModel(new DefaultComboBoxModel<String>(new String[] {"4Q"}));
		quarterComboBox.setBounds(120, 60, 90, 30);
		quarterComboBox.setEnabled(false);
		contentPanel.add(quarterComboBox);		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("确定");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						loanService.appLyUsuriousLoan((amountComboBox.getSelectedIndex()+1)*10, quarterComboBox.getSelectedItem().toString());
						String message="已申请一笔额度为"+(amountComboBox.getSelectedIndex()+1)*10+"M,借款时间为"+quarterComboBox.getSelectedItem().toString()+"的高利贷";
						JOptionPane.showMessageDialog(null, message, "提醒",
								JOptionPane.INFORMATION_MESSAGE);
						 dispose();
						
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
				refresh();
			}
			{
				JButton exitButton = new JButton("取消");
				exitButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
                          dispose();
                          refresh();
					}
				});
				exitButton.setActionCommand("Cancel");
				buttonPane.add(exitButton);
			}
		}
		addWindowListener(new WindowListener() {
			public void windowOpened(WindowEvent arg0) {
			}
			
			@Override
			public void windowIconified(WindowEvent arg0) {
			}
			
			@Override
			public void windowDeiconified(WindowEvent arg0) {
				// TODO 自动生成的方法存根
				
			}
			
			@Override
			public void windowDeactivated(WindowEvent arg0) {
				// TODO 自动生成的方法存根
				
			}
			
			@Override
			public void windowClosing(WindowEvent arg0) {
				// TODO 自动生成的方法存根
				refresh();
			}
			
			@Override
			public void windowClosed(WindowEvent arg0) {
				// TODO 自动生成的方法存根
				
			}
			
			@Override
			public void windowActivated(WindowEvent arg0) {
				// TODO 自动生成的方法存根
				
			}
		});
		setVisible(true);
	}
	private void refresh(){
		superPanel.getDashBoardPanel().setHighLoanData();
	}
}
